package edu.sctu.zcy.month201505.day20150514;

import java.util.*;

/**
 * Created by wswk on 2015/5/14.
 */
public class ListTest {

    public List courseToSelect;

    public ListTest(){

        this.courseToSelect = new ArrayList();
    }

    public void textAdd(){

        Course cr1 = new Course("1","数据结构");
        courseToSelect.add(cr1);

        Course temp = (Course) courseToSelect.get(0);
        System.out.println("添加了一门课程："+temp.id+":"+temp.name);

        Course cr2 = new Course("2","高等数学");
        courseToSelect.add(0,cr2);
        Course temp1 = (Course) courseToSelect.get(0);
        System.out.println("添加了一门课程："+temp1.id+":"+temp1.name);

        Course[] courses = {new Course("3","C语言"),new Course("4","大学英语")};
        courseToSelect.addAll(Arrays.asList(courses));
        Course temp2 = (Course) courseToSelect.get(2);
        Course temp3 = (Course) courseToSelect.get(3);
        System.out.println("添加了两门课程："+temp2.id+"："+temp2.name);
        System.out.println(temp3.id+"："+temp3.name);

    }
    public void textGet(){

        int size = courseToSelect.size();
        System.out.println("有如下课程：");
        for (int i = 0; i < size; i++) {
            Course c = (Course) courseToSelect.get(i);
            System.out.println(c.id+c.name);
        }
    }

    public void textIterator(){
        System.out.println("有如下课程1：");
        Iterator s = courseToSelect.iterator();
        while (s.hasNext()){
          Course course = (Course) s.next();

            System.out.println(course.id+course.name);
        }
    }

    public void textForEach(){
        System.out.println("有如下课程2：");
        for(Object objects:courseToSelect){

            Course course = (Course)objects;

            System.out.println(course.id+course.name);
        }


    }
    public static void main(String[] args) {


        ListTest listText = new ListTest();
        listText.textAdd();
        listText.textGet();
        listText.textIterator();
        listText.textForEach();

    }

}
